package com.badu.app.web;


import javax.validation.constraints.NotBlank;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import com.badu.app.domain.AppBanner;
import com.badu.app.service.IAppBannerService;
import com.badu.common.controller.BaseController;
import com.badu.common.utils.R;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author astupidcoder123
 * @since 2021-01-14
 */
@Validated
@Controller
@RequestMapping("/web/app/banner")
public class AppBannerController extends BaseController{

	@Autowired
	private IAppBannerService appBannerService;
	
	@ResponseBody
	@GetMapping("queryAppBannerPage")
	public R queryAppBannerPage(@RequestParam(name = "page",required = false,defaultValue = "1")Integer page
			,@RequestParam(name = "size",required = false,defaultValue = "10")Integer size,AppBanner banner) {
		appBannerService.selectPage(new Page<AppBanner>(page, size));
		Page<AppBanner> selectPage = appBannerService.selectPage(new Page<AppBanner>(page, size),new EntityWrapper<AppBanner>(banner)
				.orderBy(" bannerSort asc "));
		
		return R.ok().put("data", selectPage);
	}
	
	@ResponseBody
	@PostMapping("addAppBanner")
	public R addAppBanner(AppBanner banner,@NotBlank(message = "显示类型必填")String bannerShowType,@NotBlank(message = "是否显示必填")String bannerIsShow) {
		banner.setBannerShowType(bannerShowType);
		banner.setBannerIsShow(bannerIsShow);
		banner.setCreateUser(getUser().getUsername());
		return R.insertOrUpdateHandleResult(appBannerService.insert(banner));
	}
	
	@ResponseBody
	@PostMapping("updateAppBanner")
	public R updateAppBanner(AppBanner banner) {
		banner.setUpdareUser(getUser().getUsername());
		return R.insertOrUpdateHandleResult(appBannerService.updateById(banner));
	}
	
	@ResponseBody
	@PostMapping("deleteAppBanner")
	public R deleteAppBanner(@NotBlank(message = "id必填") String id) {
		return R.insertOrUpdateHandleResult(appBannerService.deleteById(id));
	}
}

